#include <stdio.h>
#include <math.h>

#include "vtor_key_frame.h"
#include "vtor_printf.h"

#ifdef __VTOR_KEY_FRAME__

const static VtorKeyFramePoint BatteryVoltage[] = {
	{3000, 0},
	{3650, 10},
	{3700, 20},
	{3740, 30},
	{3760, 40},
	{3795, 50},
	{3840, 60},
	{3910, 70},
	{3980, 80},
	{4070, 90},
	{4150, 100},
	{0, 0}
};


VtorKeyFramePoint tempControlArray[] = {
	{0, 100},
	{5000, 100},
	{10000, 150},
	{15000, 150},
	{20000, 200},
	{25000, 200},
	{30000, 250},
	{35000, 250},
	{40000, 150},
	{45000, 150},
	{50000, 100},
	{0, 0}
};

VtorKeyFrame laserFrame = {11, (VtorKeyFramePoint*)tempControlArray};
	
	
void VtorKeyFrame_Test(void)
{
	VtorKeyFrame demoKeyFrame = {NULL, 0};
	//VtorKeyFrame* keyFrame = malloc(sizeof(VtorKeyFrame));
	VtorKeyFrame* keyFrame = &demoKeyFrame;

	VtorKeyFrame_Insert(keyFrame, 0.0, 0.0);
	VtorKeyFrame_Insert(keyFrame, 1.0, 1.0);

	VtorKeyFrame_Insert(keyFrame, 1.0001, 2.0);
	VtorKeyFrame_Insert(keyFrame, 2.0, 4.0);

	VtorKeyFrame_Insert(keyFrame, 2.0001, 8.0);
	VtorKeyFrame_Insert(keyFrame, 3.0, 12.0);

	VtorKeyFrame_Show(keyFrame);

	for(VtorKeyType xValue = -0.5f; xValue < 4; xValue += 0.1f)
	{
		VtorKeyType yValue = VtorKeyFrame_Calc(keyFrame, xValue);
        VtorDebugChanPrintf("(%f, %f)\r\n", xValue, yValue);
	}
	free(keyFrame->points);
	
	
	VtorKeyFrame batteryKeyFrame = {NULL, 0};
    //VtorKeyFrame* keyFrame = malloc(sizeof(VtorKeyFrame));
    keyFrame = &batteryKeyFrame;
	for(int i = 0; BatteryVoltage[i].x != 0; i++)
	{
		VtorKeyFrame_Insert(keyFrame, BatteryVoltage[i].x, BatteryVoltage[i].y);
	}
    VtorKeyFrame_Show(keyFrame);

	for(VtorKeyType xValue = -0.5f; xValue < 4; xValue += 0.1f)
	{
		VtorKeyType yValue = VtorKeyFrame_Calc(keyFrame, xValue);
		VtorDebugChanPrintf("(%f, %f)\r\n", xValue, yValue);
	}
	free(keyFrame->points);
	
}

void VtorKeyFrame_Init()
{
}

#endif // __VTOR_KEY_FRAME__

